package com.iot.ammeter.view

import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.content.res.Resources
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.iot.ammeter.model.view.SelectorItem
import com.iot.ammeter.ui.components.device_bind.DropdownSelector
import com.iot.ammeter.ui.theme.AmmeterAppTheme

class DeviceBindActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            AmmeterAppTheme {
                DeviceBindScreen(listOf(0, 1, 2, 3, 4, 5))
            }
        }
    }

    companion object {
        fun launchActivity(context: Context) {
            val intent = Intent(context, DeviceBindActivity::class.java)
            context.startActivity(intent)
        }
    }
}

@Composable
private fun DeviceBindScreen(data: List<Int>) = Column(
    Modifier
        .fillMaxWidth()
        .padding(40.dp),
    horizontalAlignment = Alignment.CenterHorizontally,
) {
    Text(
        text = "添加设备",
        Modifier
            .fillMaxWidth()
            .padding(bottom = 20.dp),
        textAlign = TextAlign.Center,
        style = MaterialTheme.typography.titleLarge,
        color = MaterialTheme.colorScheme.primary
    )
    var school = remember { mutableStateOf("") }
    val items = data.map { SelectorItem(it.toString(), it) }
    DropdownSelector(items = items, defaultText = "请选择学校") {
        println(it)
    }
    DropdownSelector(items = items, defaultText = "请选择校区") {
        println(it)
    }
    DropdownSelector(items = items, defaultText = "请选择楼栋") {
        println(it)
    }
    DropdownSelector(items = items, defaultText = "请选择房间") {
        println(it)
    }
}

@Composable
@Preview(name = "light", showBackground = true)
@Preview(name = "night", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
private fun DeviceBindScreenPreview() = AmmeterAppTheme {
    DeviceBindScreen(listOf(0, 1, 2, 3, 4, 5))
}
